package template_jss;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Util {

	public static String getCurDate() {
		Date date =	new	Date ()	;
		SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd") ;
		return	formatter.format(date) ;
	}
	
	
	public static Calendar getCalendar(String aDate){
		Calendar calendar = Calendar.getInstance();
		if(aDate == null) {
			return calendar;
		}
		if(aDate.length() >= 10) {
		calendar.set( Integer.parseInt( aDate.substring(0,4) ),
					  Integer.parseInt( aDate.substring(5,7) ) -1,
					  Integer.parseInt( aDate.substring(8,10) ) );
		} else {
			calendar.set( Integer.parseInt( aDate.substring(0,4) ),
					  Integer.parseInt( aDate.substring(4,6) ) -1,
					  Integer.parseInt( aDate.substring(6,8) ) );
			
		}
		return calendar;
	}
	
	//일자 +-
	public static String incDate( String aDate, int aStep, String format ) {
		SimpleDateFormat dFormat = new SimpleDateFormat(format);
		Calendar calendar = getCalendar(aDate);
		calendar.add( Calendar.DATE , aStep );
		
		return dFormat.format(calendar.getTime());
	}
	
	public static void main(String args[]){
		//Util.getCalendar(Util.getCurDate()))
		Calendar calendar=Util.getCalendar(Util.incDate(Util.getCurDate(),-7, "yyyy-MM-dd"));
		Calendar createDt = Util.getCalendar("2012-04-01");
		System.out.println(calendar.before(createDt));
		//System.out.println(Util.getCurDate());
		
	}
}
